/* ---------------------------------------------------------------------------
   (c) Copyright 2006 ActivIdentity, Inc.
   All Rights Reserved.

   This program is an unpublished copyrighted work which is proprietary
   to ActivIdentity. This computer program includes Confidential,
   Proprietary Information and is a Trade Secret of ActivIdentity.
   Any use, disclosure, modification and/or reproduction is prohibited
   unless authorized in writing by ActivIdentity.

   WARNING:  Unauthorized reproduction of this program as well as
   unauthorized preparation of derivative works based upon the
   program or distribution of copies by sale, rental, lease or
   lending are violations of federal copyright laws and state trade
   secret laws, punishable by civil and criminal penalties.
   --------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------------
   Disclaimer

   ACTIVIDENTITY MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE 
   CONTENTS OR USE OF THIS SOFTWARE, AND SPECIFICALLY DISCLAIMS ANY EXPRESS
   OR IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
   PURPOSE. Further, ActivIdentity reserves the right to revise this software
   and to make changes to its content, at any time, without obligation to
   notify any person or entity of such revisions or changes.
   --------------------------------------------------------------------------- */

#ifndef _AK2_H_
#define _AK2_H_

#if defined(WIN32) || defined(_WIN32_WCE)
	#include <windows.h>
#else
	#ifndef __UNIX_
		#define __UNIX_
		#define CALLBACK
		#define FALSE 0
		#define TRUE 1
		typedef int BOOL;
	#endif
#endif
#include "acm.h"

#ifdef	__cplusplus 
extern "C" {
#endif

/*---------------------- Return Value ----------------------- */
enum
{
	AK_ERR_NOERROR = 0,						/* No Error */

	AK_ERR_INTERNAL_ERROR = 1,				/* Internal error */
	AK_ERR_BAD_PARAMETER = 2,				/* Bad parameter */

	AK_ERR_SYNCHRONIZATION_FAILURE = 10,	/* Synchronization failure */
	AK_ERR_BAD_CHALLENGE_CD = 11,			/* Bad challenge check digit */
	AK_ERR_BAD_AUTH_CODE_CD = 12,			/* Bad code check digit  */
	AK_ERR_BAD_AUTH_CODE = 13,				/* Bad code */
	AK_ERR_BAD_COUNTER_VALUE = 14, 			/* Bad counter value */
	AK_ERR_WRONG_PIN = 15					/* Wrong "software" PIN value */
};

#define AK_SERVICE_SUCCEEDED AK_ERR_NOERROR

#define AK_ERR_BAD_CERTIF_CODE AK_ERR_BAD_AUTH_CODE

/* Default synchronization counter value */
#define AK_SYNC_COUNTER_DEFAULT_VALUE -1

/* Default synchronization clock value */
#define AK_SYNC_CLOCK_DEFAULT_VALUE -1

#define AK_ACI_DES_BLOCK8		8

/* ------ akapi.c  Prototypes ---------------------------- */

int CALLBACK akAuthAsyncCheckCode (	
	const char *pszAuthCode,	
	const strAuthAsynchronous *psAuthAsync,
	const char *pszChallenge
	);		

int CALLBACK akAuthAsyncGetCode (
	const char *pszChallenge,	
	const strAuthAsynchronous *psAuthAsync, 
	char *pszAuthCode
	);      

int CALLBACK akAuthSyncCheckCode ( 
	const char *pszAuthCode,		
	strAuthSynchronous *psAuthSync,
	unsigned long ulClock
	);

int CALLBACK akExtAuthSyncCheckCode ( 
	const char *pszAuthCode,		
	strExtAuthSynchronous *psExtAuthSync,
	unsigned long ulClock
	);

int CALLBACK akAuthSyncGetCode (	
	strAuthSynchronous *psAuthSync,
	int nSynchroCounter,
	int nSynchroClock,
	unsigned long ulClock,
	char *pszAuthCode
	);      

int CALLBACK akExtAuthSyncGetCode (	
	strExtAuthSynchronous *psExtAuthSync,
	int nSynchroCounter,
	int nSynchroClock,
	unsigned long ulClock,
	char *pszAuthCode
	);      

int	CALLBACK akGetUnlockCode(	
	const strUnlock *psUnlockParam,
	const char *pszChallenge,
	char *pszUnlockCode
	);

int CALLBACK akSyncEventCounters (	
	strSyncEventCnt *psCounterParam,
	const unsigned int ulCounter
	);  

int CALLBACK akGetServerAuthCode ( 
	const strVerifServer *psVerifServer,
	const char *pszChallenge,
	char *pszServerAuthCode
	);   

int CALLBACK akGetOffsetTokenGlobal (	
	const char *pszTokenClock,					
	unsigned long ulTime,								
	int *pnOffsetTokenGlobal
	);

int CALLBACK akSyncCounterAndOffset (
	const char *pszAuthCode,	
	strAuthSynchronous *psAuthSync,
	const unsigned long ulClock,	
	const int nCounterRange, 
	const StrClockRange *psClockRange 
	);

int CALLBACK akExtSyncCounterAndOffset (
	const char *pszAuthCode,	
	strExtAuthSynchronous *psExtAuthSync,
	const unsigned long ulClock,	
	const int nCounterRange, 
	const StrClockRange *psClockRange 
	);

int CALLBACK akGetOffsetTokenSpecific( 
	const char *pszTokenClock,
	unsigned long ulClock,
	int *pnOffsetTokenSpecific
	);

int CALLBACK akGetVersion( 
	char *pszVersion, 
	unsigned int *unVersion,
	char *pszCopy, 
	char *pszComment
	);

int CALLBACK akGetChallenge (
	int nChallengeSize,
	int nChalCd,
	char *pszChallenge
	);  

int CALLBACK akGetChallengeEx ( 
	IN int nChallengeSize,	/* Size of the challenge */
	IN int nChalCd,			/* Challenge check digit */
	OUT char *pszChallenge,	/* Return challenge string */
	IN int nAuthType);

int CALLBACK akGetChallengeFromRandValues ( 
	int nChalSize,
	unsigned int nRandValue,
	unsigned int nRandMax,
	char *pszChallenge
	);

/* ------ akapicer.c  Prototypes ---------------------------- */

int CALLBACK akCertificateAsyncCheck(	
	const char *pszCertificate, 
	const strCertifData *psData,  
  	const strCertifAsync *psCertifAsync
	);

int CALLBACK akCertificateSyncCheck(
	const char *pszCertificate, 
	const strCertifData *psData,      
	strCertifSync *psCertifSync,
	unsigned long ulClock
	);

int CALLBACK akExtCertificateAsyncCheck(	
	const char *pszCertificate, 
	const strExtCertifData *psData,  
  	const strExtCertifAsync *psExtCertifAsync
	);

int CALLBACK akExtCertificateSyncCheck(
	const char *pszCertificate, 
	const strExtCertifData *psData,      
	strExtCertifSync *psExtCertifSync,
	unsigned long ulClock
	);

int CALLBACK akExtCertificateSyncCounterAndOffset(
	INOUT strExtCertifSync *psExtCertifSync,
	IN const strExtCertifData *psData,
	IN const char *pszCertificate,
	IN const unsigned long ulClockInSeconds,
	IN const int nCounterRange,
	IN const StrClockRange *psClockRange);

int akAuthEMVAsyncCheckCode ( 
	IN strEMVAuth *sAuthAsync,	/* Authentication Parameters */
	IN acEMVAuthContext* pCBContext);

int akAuthEMVSyncCheckCode ( 
	IN strEMVAuth *sAuthAsync,	/* Authentication Parameters */
	IN acEMVAuthContext* pCBContext,
	IN unsigned int ulClock);

int akGetJavaCardDynamicUnlockCode(	
	const char *pszKey,
	const char *pszChallenge,
	char *pszUnlockCode);

int akGetCryptoDynamicUnlockCode(	
	const char *pszKey,
	const char *pszChallenge,
	char *pszUnlockCode);

/* ------------------ ak2oath ------------------------------ */

int CALLBACK akHOTPAuthSyncGetCode (	
	strHOTPAuth *psHOTP,
	unsigned long ulClock, /* reserved for future use */
	char *pszAuthCode
	);

int CALLBACK akHOTPSyncCounterAndOffset (
	const char *pszAuthCode,	
	strHOTPAuth *psHOTPAuthSync,
	const unsigned long ulClock,
	const int nCounterRange, /* reserved for future use */
	const StrClockRange *psClockRange /* reserved for future use */
	);

int CALLBACK akHOTPAuthSyncCheckCode ( 
	const char *pszAuthCode,		
	strHOTPAuth *psHOTP,
	unsigned long ulClock /* reserved for future use */
	);

/* --------------------------------------------------------- */

#ifdef	__cplusplus
}
#endif

#endif /* _AK2_H_ */
